package com.zhentao;


import io.minio.MinioClient;
import io.minio.ObjectWriteResponse;
import io.minio.PutObjectArgs;

import java.io.FileInputStream;

public class MinioApplication {

    public static void main(String[] args) {
        try {

            //1.创建minio的客户端
            MinioClient minioClient = MinioClient.builder()
                    .credentials("minioadmin", "minioadmin")
                    .endpoint("http://192.168.159.128:19000")
                    .build();

            //创建 FileInputStream
            FileInputStream fileInputStream = new FileInputStream("E://11.html");

            //2.执行上传操作  0上传的参数
            PutObjectArgs putObjectArgs = PutObjectArgs.builder()
                    //桶名词 与minio创建的名词一致
                    .bucket("testapi")
                    //文件名
                    .object("11.html")
                    //文件类型
                    .contentType("text/html")
                    //在构建InputStream时，会进行分片操作，分片大小不能小于5MB，大于5GB
                    //partSize传入-1，默认按照5MB进行分割
                    .stream(fileInputStream, fileInputStream.available(), -1)
                    .build();

            //3. 执行上传才走  1 上传
            ObjectWriteResponse response = minioClient.putObject(putObjectArgs);
            System.out.println("response: " + response);


            //获取访问路径
            String url = minioClient.getObjectUrl(putObjectArgs.bucket(), putObjectArgs.object());
            System.out.println("path: " + url);

        } catch (Exception e) {
            e.printStackTrace();
        }




    }
}